package com.suxii.adapter.animator;


import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.RecyclerView;

public class FadeInAnimator extends DefaultItemAnimator {
    @Override
    public boolean animateChange(@NonNull RecyclerView.ViewHolder oldHolder, @NonNull RecyclerView.ViewHolder newHolder, @NonNull ItemHolderInfo preInfo, @NonNull ItemHolderInfo postInfo) {
        return super.animateChange(oldHolder, newHolder, preInfo, postInfo);
    }

    @Override
    public boolean animateAdd(@NonNull RecyclerView.ViewHolder holder) {
        holder.itemView.setAlpha(0f);
        holder.itemView.animate().alpha(1f).setDuration(getAddDuration()).setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animator) {
                dispatchAddFinished(holder);
            }
        }).start();
        return true;
    }

    @Override
    public boolean animateRemove(@NonNull RecyclerView.ViewHolder holder) {
        holder.itemView.animate().alpha(0f).setDuration(getRemoveDuration()).setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animator) {
                dispatchRemoveFinished(holder);
            }
        }).start();
        return true;
    }
}
